package com.apes.scm.masterdata.product.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.fileserver.File;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：品牌
 *
 * @author HuJianlin
 * @create 2018-03-15 16:00
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = "mas_brand")
public class Brand extends Model {
    public static final String CONST_TABLE_NAME = "mas_brand";

    @Id
    @Column(name = "id", length = 16)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "品牌编码")
    @Comment("品牌编码")
    private String id;  //品牌编码

    @Column(name = "name", nullable = false, length = 120)
    @Comment("品牌名称")
    private String name; //品牌名称

    @Column(name = "en_name", length = 200)
    @Comment("英文名称")
    private String enName; //英文名称

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "brand_type_id", referencedColumnName = "id")
    @Comment("品牌类型")
    private BrandType brandType;  //品牌类型

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("有效标记")
    private boolean valid = true; //有效

    @File
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "logo", columnDefinition = "CLOB")
    @Comment("LOGO")
    private String logo;   // LOGO

    @File
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "book", columnDefinition = "CLOB")
    @Comment("授权书")
    private String book; // 授权书

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "quality", referencedColumnName = "id")
    private Enumeration quality; //品质

    @ManyToOne(fetch = FetchType.LAZY)
    @Comment("品质(老系统使用)")
    @JoinColumn(name = "character", referencedColumnName = "id")
    private Enumeration character; //品质

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "sub_quality", referencedColumnName = "id")
    @Comment("细分品质(老系统使用)")
    private Enumeration subQuality; //细分品质
}
